// pages/greeting-card-list/greeting-card-list.js
var util = require("../../utils/util.js");
Page({

    /**
     * 页面的初始数据
     */
    data: {
        choosed: '0',
        currentPic: '',
        origin: '',
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {
        if (options.origin) {
            this.setData({
                origin: options.origin
            })
        }
        this.getCardList()
    },
    chooseThis: function(e) {
        const _this = this;
        var currentId = e.currentTarget.dataset.id;
        var cardEnvelopeUrl = e.currentTarget.dataset.envelop;
        wx.setStorageSync("giveCardId", currentId);
        if (_this.data.origin == 'littleThought') {
            wx.navigateTo({
                url: "/pages/greeting-card/greeting-card?id=" + currentId + '&envelopUrl=' + cardEnvelopeUrl + '&origin=' + 'littleThought'
            })
        } else {
            wx.navigateTo({
                url: "/pages/greeting-card/greeting-card?id=" + currentId + '&envelopUrl=' + cardEnvelopeUrl
            })
        }

    },
    // toGreetingCard: function() {
    //     wx.navigateTo({
    //         url: "/pages/greeting-card/greeting-card"
    //     })
    // },

    // chooseThis: function(e) {
    //     const _this = this;
    //     var currentPic = e.currentTarget.dataset.url;
    //     var choosed = e.currentTarget.dataset.key;
    //     _this.setData({
    //         currentPic,
    //         choosed
    //     })
    // },
    getCardList: function() {
        const _this = this;
        util.request(getApp().api.greeting.cardList).then(
            function(res) {
                if (res.code == 200) {
                    _this.setData({
                        card_list: res.data,
                    });
                } else {
                    wx.showToast({
                        title: res.msg, //提示的内容,
                        icon: "none", //图标,
                        //duration: 1500, //延迟时间,
                        mask: false, //显示透明蒙层，防止触摸穿透,
                    });
                    setTimeout(function() {
                        wx.hideToast();
                    }, 1500);
                    return
                }
            }
        );
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function() {

    },
})